#第一题、将之前封装的MyMath类中的实例方法改为静态方法, 体会两者的区别.
class ParamsError(object):
    pass


class MyMath:

    @staticmethod
    def add(a, b):
        return a + b

    @staticmethod
    def sub(a, b):
        return a - b

    @staticmethod
    def mul(a, b):
        return a * b

    @staticmethod
    def div(a, b):
        try:
            return a / b
        except ZeroDivisionError:
            raise ParamsError("除法中，分母不能为0")
        finally:
            print('div None')

    @staticmethod
    def remainder(a, b):
        return a ** b

    @staticmethod
    def sqare(a, b):
        return a ** b

print(MyMath.add(1, 2))
print(MyMath.sub(4, 2))
print(MyMath.mul(1, 2))
print(MyMath.div(4, 2))
print(MyMath.remainder(2, 4))
print(MyMath.sqare(4, 1/2))

#第二题、为上节课自定义类添加以下功能:
#添加类属性
#添加类私有属性
#添加类方法或者类的私有属性
#在__init__方法中初始化实例属性
#在__init__方法中绑定私有实例属性
#在自定义类中实现__str__, 自定义输出格式

class Cup:
    GlassCup = True
    __price = {"mate": 200}
    def __init__(self, materail, price):

        self. materail = materail
        self. __price = price

    @classmethod
    def __new__(cls, *args, **kwargs):
        print("杯子很好用")
        return super().__new__(cls)

    def __str__(self):
        return "杯子材质是%s , 价格是%d元" % (self. materail, self. __price)


print(Cup. _Cup__price)
A_Cup = Cup("玻璃", 200)
print(A_Cup)